package de.nak.notendb.action;

import com.opensymphony.xwork2.ActionSupport;

import de.nak.notendb.service.exceptions.AccessToDatabaseNotPossibleException;
import de.nak.notendb.service.interfaces.ISupportService;

/**
 * Action for reset functionality
 * 
 * @author Christian Baumhof
 * 
 */
public class ResetAction extends ActionSupport {

	/**
	 * The generated serialVersionUID
	 */
	private static final long serialVersionUID = 8528028389361176466L;

	/**
	 * True, if reset was successful.
	 */
	private Boolean resetDbSuccess;

	/**
	 * True, if an error occurred during reset.
	 */
	private Boolean resetDbFailed;

	/**
	 * The service for the reset functionality.
	 */
	private ISupportService supportService;

	@Override
	public String execute() throws Exception {
		try {
			supportService.reset();
			resetDbSuccess = true;
			resetDbFailed = false;
		} catch (AccessToDatabaseNotPossibleException exception) {
			resetDbFailed = true;
			resetDbSuccess = false;
		}
		return SUCCESS;
	}

	public String showConfirmation() throws Exception {
		resetDbSuccess = false;
		resetDbFailed = false;
		return SUCCESS;
	}

	/**
	 * Setter for the SupportService.
	 * 
	 * @param supportService
	 *            the Service for the reset functionality.
	 */
	public void setSupportService(ISupportService supportService) {
		this.supportService = supportService;
	}

	/**
	 * Returns true if reset was successful.
	 * 
	 * @return true if an error occurred during reset.
	 */
	public Boolean getResetDbSuccess() {
		return resetDbSuccess;
	}

	/**
	 * Returns true if an error occurred during reset.
	 * 
	 * @return true if an error occurred during reset.
	 */
	public Boolean getResetDbFailed() {
		return resetDbFailed;
	}

}
